import requests

# url = 'http://finley.pw:8888'

host = 'http://localhost:8080'

cookies = None


def test_apply():
    params = {
        'stu_name': '李约翰',
        'stu_id': '14130140123',
        'stu_phone': '15091092343',
        'parent_phone': '15192073343',
        'start_time': '2016-11-11 12:00',
        'stop_time': '2016-11-12 12:00',
        'reason': '失恋了，伤心',
        'location': '7号楼',
    }
    r = requests.post(host + '/apply/', data=params)
    print(r.text)


def test_query():
    global cookies
    params = {
        'stu_name': '李约翰',
        'stu_id': '14130140123',
    }
    r = requests.post(host + '/query/', data=params)
    cookies = r.cookies
    print(r.text)
    print(cookies)


def test_error_query():
    global cookies
    params = {
        'stu_name': '李约翰',
        'stu_id': '14130140133',
    }
    r = requests.post(host + '/query/', data=params)
    cookies = r.cookies
    print(r.text)
    print(cookies)


def test_query_detail():
    global cookies
    test_query()
    r = requests.get(host + '/query/1/detail/', cookies=cookies)
    print(r.text)


def test_admin_login():
    global cookies
    params = {
        'username': 'admin',
        'password': 'admin'
    }
    r = requests.post(host + '/admin/login/', data=params)
    cookies = r.cookies
    print(r.text)
    print(cookies)


def test_admin_list():
    global cookies
    test_admin_login()
    r = requests.get(host + '/admin/list/', cookies=cookies)
    print(r.text)


def test_admin_inspect():
    global cookies
    test_admin_login()
    params = {
        'demand_id': '1',
        'state': '1',
        'director_comment': '年轻人naive'
    }
    r = requests.post(host + '/admin/inspect/', data=params, cookies=cookies)
    print(r.text)


def test_admin_history():
    global cookies
    test_admin_login()
    params = {
        'start_time': '2016-01-01 12:00',
        'stop_time': '2016-12-30 12:00',
        'limit': 10
    }
    r = requests.post(host + '/admin/history/', data=params, cookies=cookies)
    print(r.text)


def test():
    test_apply()
    test_query()
    test_error_query()
    test_query_detail()

    test_admin_login()
    test_admin_list()
    test_admin_inspect()
    test_admin_history()


if __name__ == '__main__':
    test()